package com.suge.home.module.screen.json;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.suge.common.constant.LoginConstants;
import com.suge.home.module.screen.Index;
import com.suge.user.dao.dataobject.UserDO;
import com.suge.user.manager.UserManager;

public class TestAB {


	private static final Logger logger = LoggerFactory.getLogger(Index.class);

	@Autowired
    private HttpServletRequest request;
	@Autowired
	private UserManager userManager;
	
	public void execute(Context context, Navigator nav) {
		
		logger.error("welcome back!");
		
		String userName = (String) request.getSession().getAttribute(LoginConstants.ATTRIBUTE_USER_NAME);
		
		String userId = (String) request.getSession().getAttribute(LoginConstants.ATTRIBUTE_USER_ID_NUM);

		if(userName==null || userId==null){
			logger.error("Go to login!");
			nav.redirectToLocation("http://container.open.taobao.com/container?appkey=21430427&encode=utf-8");
			return;
		}
		
		UserDO userDO = userManager.getAppUserByUserId(Long.parseLong(userId));
		context.put("userDO", userDO);
		
	}


	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}


	public HttpServletRequest getRequest() {
		return request;
	}


	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}


	public UserManager getUserManager() {
		return userManager;
	}


}
